const formatTime = (date,number) => {
	const year = date.getFullYear()
	const month = date.getMonth() + 1
	const day = date.getDate() + number
	return [year, month, day].map(formatNumber).join('-')
}
const formatDate = date => {
	const year = date.getFullYear()
	const month = date.getMonth() + 1
	const day = date.getDate()
	const a = new Array("日", "一", "二", "三", "四", "五", "六");
	const week = date.getDay();
	return "星期" + a[week] + " " + month + "月" + day + "日"
}

const tomorrowDate = date => {
	const year = date.getFullYear()
	const month = date.getMonth() + 1
	const day = date.getDate() + 1
	const a = new Array("日", "一", "二", "三", "四", "五", "六");
	const week = date.getDay();
	return "星期" + a[week] + " " + month + "月" + day + "日"
}

const yesterdayDate = date => {
	const year = date.getFullYear()
	const month = date.getMonth() + 1
	const day = date.getDate() - 1
	const a = new Array("日", "一", "二", "三", "四", "五", "六");
	const week = date.getDay();
	return "星期" + a[week] + " " + month + "月" + day + "日"
}
const formatHour = (date) => {
	let hour  = date.getHours(); 
    let minute = date.getMinutes(); 
    if(hour < 10){
    		hour = "0" + hour;
    }
    if(minute < 10){
    		minute = "0" + minute;
    }
	return hour+":"+minute
}
const formatSeconds = (temp) => {
	let date = new Date(temp);
    let minute = date.getMinutes();
    let seconds = date.getSeconds();
    if(minute < 10){
    		minute = "0"+ minute;
    }
    if(seconds < 10){
    		seconds = "0"+ seconds;
    }
	return minute+":"+seconds
}

const formatMinute = (date) => {
	let d = new Date(date);
	return formatTime(d,0)+" "+formatHour(d)
}

const formatEndTime = (date) => {
	let d = new Date(date);
	return formatDate(d)+" "+formatHour(d)
}

const formatNumber = n => {
	n = n.toString()
	return n[1] ? n : '0' + n
}

module.exports = {
	formatTime: formatTime,
	formatDate: formatDate,
	tomorrowDate:tomorrowDate,
	yesterdayDate:yesterdayDate,
	formatHour:formatHour,
	formatSeconds:formatSeconds,
	formatEndTime:formatEndTime,
	formatMinute:formatMinute,
}